﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MySoftWare.BaseModel;
using MySoftWare.MVCCommon;
using MySoftWare.MVCCommon.Repository;

namespace MySoftWare.SimpleMVC.Controllers
{
    public class UserController : Controller
    {
        //
        // GET: /User/
        private IUserRepository AutoFacUser;
        public UserController(IUserRepository UserRepository)
        {
            AutoFacUser = UserRepository;
        }

        #region 用户组管理
        public ActionResult UserGroup()
        {
            return View();
        }

        /// <summary>
        /// 获取用户组列表
        /// </summary>
        /// <returns></returns>
        public ActionResult GetUserGroupList()
        {
            List<UserGroupModel> List = new List<UserGroupModel>();
            List = AutoFacUser.GetUserGroupList();
            return Json(List, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 添加用户组信息
        /// </summary>
        /// <param name="UserGroup"></param>
        /// <returns></returns>
        public ActionResult AddUserGroupInfo(UserGroupModel UserGroup)
        {
            UserGroup.AddDate = DateTime.Now;
            UserGroup.AddUser = "admin";
            UserGroup.UpdateDate = DateTime.Now;
            UserGroup.UpdateUser = "admin";
            AutoFacUser.AddUserGroup(UserGroup);
            return Content("OK");
        }

        /// <summary>
        /// 删除用户组可多个
        /// </summary>
        /// <param name="DeleteUserGroupID"></param>
        /// <returns></returns>
        public ActionResult DeleteUserGroup(string DeleteUserGroupID)
        {
            AutoFacUser.DeleteUserGroup(DeleteUserGroupID);   
            return Content("OK");
        }

        /// <summary>
        /// 获取用户组详细信息
        /// </summary>
        /// <param name="GroupID"></param>
        /// <returns></returns>
        public ActionResult GetUserGroupDetail(string GroupID)
        {
            UserGroupModel UserGroup = new UserGroupModel();
            UserGroup = AutoFacUser.GetUserGroupDetail(GroupID);
            return Json(UserGroup, JsonRequestBehavior.AllowGet);
        }

        public ActionResult UpdateUserGroup(UserGroupModel UserGroup)
        {
            UserGroup.AddUser = "admin";
            UserGroup.AddDate = DateTime.Now;
            UserGroup.UpdateUser = "admin";
            UserGroup.UpdateDate = DateTime.Now;
            if (AutoFacUser.UpdateUserGroup(UserGroup))
            {
                return Content("OK");
            }
            else
            {
                return Content("No");
            }
            ///
        }
        #endregion

    }
}
